package likou.offer;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @Info:
 * @Author: Tangxz
 * @Date: 2020/09/04 22:53
 */
public class _59 {
    Deque<Integer> stack;
    Deque<Integer> stackMax;

    public _59() {
        stack = new LinkedList<>();
        stackMax = new LinkedList<>();
    }

    public int max_value() {
        return stackMax.size() == 0 ? -1 : stackMax.peekLast();
    }

    public void push_back(int value) {
        stack.add(value);
        int nowMax = stackMax.size() == 0 ? Integer.MIN_VALUE : stackMax.peekLast();
        if (nowMax <= value) {
            stackMax.add(value);
        }
    }

    public int pop_front() {
        int top = stack.size() == 0 ? -1 : stack.pop();
        if (top != -1 && stackMax.peekFirst() == top) {
            stackMax.pollFirst();
        }
        return top;
    }
}
